package com.csw.android.dev_utils.ui.databinding

import android.os.Bundle
import android.view.View
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import com.csw.android.dev_utils.ui.BaseActivity

/**
 * 基于dataBinding实现布局的Activity
 */
abstract class DataBindingActivity<T : ViewDataBinding> : BaseActivity() {
    /**
     * dataBinding实例，已在initView初始化
     */
    protected var dataBinding: T? = null
        private set

    override fun initView(rootView: View, savedInstanceState: Bundle?) {
        super.initView(rootView, savedInstanceState)
        dataBinding = DataBindingUtil.bind(rootView)
        dataBinding?.lifecycleOwner = this
    }

    override fun onDestroy() {
        dataBinding?.unbind()
        dataBinding = null
        super.onDestroy()
    }

}